package Huihu.src.网络编程;

import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.ServerSocket;
import java.net.Socket;

//服务端
public class TcpServer {
    public static void main(String[] args) throws Exception {
        //创建端口号
        ServerSocket serverSocket=new ServerSocket(7788);
        //接收客户端请求
        Socket socket=serverSocket.accept();
        //接收文件
        InputStream is=socket.getInputStream();
        OutputStream os=new FileOutputStream("Libs/k.jpg");
        byte [] bus=new byte[1024];
        int len;
        while ((len = is.read(bus)) != -1) {
            os.write(bus,0,len);
        }
        os.close();
        is.close();
        socket.close();
    }
}
